﻿using Ross.EntityFramework;
using Ross.EntityFramework.Model;
using Ross.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Security;

namespace Ross.BSCSystem.Controllers
{
    public class BSCController : BaseApiController
    {
        [HttpPost]
        public JsonResult<ResultDto<Service.Dto.oUser>> Login([FromBody] Service.Dto.LoginVM vm)
        {
            ResultDto<Service.Dto.oUser> result = new ResultDto<Service.Dto.oUser>();
            using (UsersService serv = new UsersService(dbContextStr))
            {
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(0, vm.username, DateTime.Now,
                            DateTime.Now.AddHours(1), true, string.Format("{0}&{1}&{2}", vm.username, vm.password, vm.year),
                            FormsAuthentication.FormsCookiePath);
                string token = FormsAuthentication.Encrypt(ticket);
                result = serv.Login(vm, token);
            }
            return Json(result);
        }

        
    }
}
